#include <stdio.h>
#include <map>

int main()
{
    /* The condition for a directed tree is:
     * 1.  The graph is empty, or
     * 2a. There is exactly one node (root) with no in-edge, and
     * 2b. All the other nodes have exactly one in-edge.
     */
    std::map<int,int> in_degree;    
    int from, to, t;
    for (t = 1; scanf("%d %d", &from, &to) == 2 && from >= 0 && to >= 0; t++)
    {
        int count_0 = 0; /* number of nodes with in-degree = 0 */
        int count_1 = 0; /* number of nodes with in-degree = 1 */
        while (!(from == 0 && to == 0))
        {
            in_degree[from] += 0;
            in_degree[to] += 1;
            scanf("%d %d", &from, &to);
        }
        for (std::map<int,int>::iterator it = in_degree.begin(); 
             it != in_degree.end(); ++it)
        {
            if (it->second == 0)
                ++count_0;
            else if (it->second == 1)
                ++count_1;
        }
        bool is_tree = (in_degree.size() == 0) || 
            (count_0 == 1 && count_0 + count_1 == in_degree.size());
        printf("Case %d %s a tree.\n", t, is_tree? "is" : "is not");
        in_degree.clear();
    }
    return 0;
}
